FROM ghcr.io/graalvm/native-image-community:21.0.2-muslib as builder

WORKDIR /app

ARG MAVEN3_VERSION="3.9.6"
ARG MAVEN3_CLI_URL="https://archive.apache.org/dist/maven/maven-3/${MAVEN3_VERSION}/binaries/apache-maven-${MAVEN3_VERSION}-bin.tar.gz"
ENV PATH="/app/apache-maven-${MAVEN3_VERSION}/bin:${PATH}"

ADD ${MAVEN3_CLI_URL} ./

RUN tar xzvf /app/apache-maven-${MAVEN3_VERSION}-bin.tar.gz
RUN rm -f /app/apache-maven-${MAVEN3_VERSION}-bin.tar.gz

COPY ./pom.xml .
COPY ./src src

RUN mvn native:compile -Pnative

FROM alpine:3.19.1


WORKDIR /
COPY --from=builder /app/target/app /app

ENTRYPOINT ["/app"]